#include<stdlib.h>
#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>

void removeZeros(int arr[], int *n) {
    int count = 0; // 用于记录非零元素的数量

    // 遍历数组
    for (int i = 0; i < *n; i++) {
        // 如果当前元素不是0，则将其移动到前面
        if (arr[i] != 0) {
            arr[count] = arr[i];
            count++; // 增加非零元素的计数
        }
    }

    // 更新数组的长度，去掉所有0元素后的长度
    *n = count;
}

#include <stdio.h>
#include <string.h>

void removeNullChars(char *str) {
    int count = 0;
    for (int i = 0; str[i]; i++) {
        if (str[i] != '\0') {
            continue;
        }else {
            str[count++] = str[i];
        }
    }
    // str[count] = '\0';
}

void removeChar(char *str, char remove) {
    int count = 0;
    for (int i = 0; str[i]; i++) {
        if (str[i] != remove) {
            str[count++] = str[i];
        }
    }
    // str[count] = '\0';
}


int main(int argc,char *argv[]){

    int arr[10] = {1,2,3,4,5,6,7,8,9,10};
    int n = sizeof(arr) / sizeof(arr[0]);

    printf("Before sorting:\n");
    arr[4] = 0;
    arr[7] = 0;
    //打印长度为10的数组
    for(int i=0;i<10;i++){
        printf("%d ",arr[i]);
    }
    removeZeros(arr, &n);
    for (size_t i = 0; i < n; i++)
    {
        printf("%d ",arr[i]);
    }



    printf("arr size: %ld\n",sizeof(arr)/sizeof(arr[0]));
    printf("------------------、\n");

    char str[] = "Hello World";

    // removeNullChars(str);
    removeChar(str, 'l');
    printf("现在字符串为: %ld\n", sizeof(str)/sizeof(char));
    for (size_t  i = 0; i < sizeof(str)/sizeof(char); i++)
    {
        printf("%c\n", str[i]);
    }
    printf("\n--------------\n");

    // printf("现在字符串为: %s\n", str);

    return 0;
}